<?php
/**
 * Created by PhpStorm.
 * User: wangjiangtao
 * Date: 2022/2/21
 * Time: 14:58
 */

namespace App\Console\Commands;
use App\Http\Model\Hint;

use App\Http\Model\Mall;
use App\Http\Model\User;
use App\Http\Services\GoodsIncomeServices;
use Illuminate\Console\Command;

class UserGoodsIncome extends Command{

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'User:Goods:Income';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '可升级商品(坐骑)佩戴升级';
    protected $GoodsIncomeServices = null;


    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
        $this->GoodsIncomeServices = new GoodsIncomeServices();
    }

    public function handle(){
        $date = date('Y-m-d H:s:i');
        echo  $date. '-开始' . PHP_EOL;
        // 获取所有在线用户
        $this->userModel = new User();
        $OnLineuser = $this->userModel->getOnlineUserArr();//在线
        if ($OnLineuser){
            $GoodsIncomeServices = new GoodsIncomeServices();
            $modelMall = new Mall();

            foreach ((array)$OnLineuser as $key => $UID) {
                $goods = $modelMall -> getGoodsAttire($UID);
                if ($goods){
                    foreach ((array)$goods as $ginfo){

                        $isUpgrade = $ginfo['is_upgrade'] ?? 0;
                        if (!$isUpgrade){
                            continue;
                        }
                        $GID = $ginfo['goods_id'];

                        // 佩戴装扮 更新任务
                        $GoodsIncomeServices -> taskUserGoodsIncomeChange($UID, $GID, '用户持续在线');
                    }
                }
            }
        }

        echo date('Y-m-d H:s:i') . '-结束（'. $date  . PHP_EOL;

        return true;
    }





}
